//
//  YBReleaseMeetingPreViewController.m
//  GongXinDangJian
//
//  Created by apple on 17/12/9.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "YBReleaseMeetingPreViewController.h"

@interface YBReleaseMeetingPreViewController ()

/**  back  */
@property (strong, nonatomic) UIScrollView  *backScrollView;

@property (nonatomic , strong) UIButton * modifyButton;
@end

@implementation YBReleaseMeetingPreViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.titlelabel.text = self.model.TITLE;
    [self ybInitUserInterface];
}


-(void)ybInitUserInterface{
    [self.view addSubview:self.backScrollView];
    
    UILabel * currentLabel = nil;
    NSArray * titleArray = @[@"" ,@"会议内容:" , @"发布对象人数:" , @"会议地点:" , @"会议时间:" , @"联 系 人:" , @"联系电话:" , @"发布单位:" , @"发布日期:" , @"截止日期:" , @"发布对象:" , @"上传照片(不得上传任何涉密照片):"];
    
    NSString * tempString = @"";
    for (YBPeopleInfoModel * model in self.peopleArray) {
        tempString = [NSString stringWithFormat:@"%@%@-%@、" , tempString , model.F_DEPT_NAME , model.NAME];
    }
    if (tempString.length > 0) {
        tempString = [tempString substringToIndex:(tempString.length - 1)];
    }
    
    NSArray * dataArray = @[self.model.TITLE , self.model.CONTENT , [NSString stringWithFormat:@"%ld" , self.peopleArray.count] , self.model.ADDRESS , self.model.HY_START_TIME , self.model.CONTACT_NAME , self.model.CONTACT_MOBILE , self.model.PUBLISH_UNIT , self.model.START_TIME , self.model.END_TIME , tempString , @""];
    
    for (int i = 0 ; i < titleArray.count; i ++) {
        if (i == titleArray.count - 1) {
            if (self.model.UPLOAD_FILES.count == 0) {
                break;
            }
        }
        NSString * theString = [NSString stringWithFormat:@"%@%@" , titleArray[i] , dataArray[i]];
        UILabel * label = [ToolClass creatLabelWithFrame:CGRectMake(0, 0, [UIScreen zj_screenWith] - ItemWidth * 60, ItemHeight * 60) font:15 textColor:[UIColor textBlackColor] text:theString];
        CGFloat theHeight = [theString boundingRectWithSize:CGSizeMake([UIScreen zj_screenWith] - ItemWidth * 60, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : LYPFONT(15)} context:nil].size.height;
        [self.backScrollView addSubview:label];
        if (i == 0) {
            label.sd_layout.leftSpaceToView(self.backScrollView , ItemWidth * 30).topSpaceToView(self.backScrollView , ItemHeight * 15).widthIs([UIScreen zj_screenWith] - ItemWidth * 60 + 1).heightIs(theHeight + 1);
        }
        else{
            label.sd_layout.leftSpaceToView(self.backScrollView , ItemWidth * 30).topSpaceToView(currentLabel , ItemHeight * 30).widthIs([UIScreen zj_screenWith] - ItemWidth * 60 + 1).heightIs(theHeight + 1);
        }
        currentLabel = label;
    }
    
    UIImageView * currentImageView = nil;
    
    for (int j = 0; j < self.model.UPLOAD_FILES.count; j ++) {
        UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen zj_screenWith] - ItemWidth * 400, ItemHeight * 400)];
        imageView.image = [UIImage imageWithData:self.model.UPLOAD_FILES[j].FILE_PATH];
        [self.backScrollView addSubview:imageView];
        if (j == 0) {
            imageView.sd_layout.leftSpaceToView(self.backScrollView , [UIScreen zj_screenWith] * 0.25).topSpaceToView(currentLabel , ItemHeight * 30).widthIs([UIScreen zj_screenWith] * 0.5).heightIs([UIScreen zj_screenHeight] * 0.5);
        }
        else{
            imageView.sd_layout.leftSpaceToView(self.backScrollView , [UIScreen zj_screenWith] * 0.25).topSpaceToView(currentImageView , ItemHeight * 30).widthIs([UIScreen zj_screenWith] * 0.5).heightIs([UIScreen zj_screenHeight] * 0.5);
        }
        currentImageView = imageView;
    }
    
    [self.backScrollView addSubview:self.modifyButton];
    
    if (!currentImageView) {
        self.modifyButton.sd_layout.leftSpaceToView(self.backScrollView , [UIScreen zj_screenWith] * 0.25).topSpaceToView(currentLabel , ItemHeight * 60).widthIs([UIScreen zj_screenWith] * 0.5).heightIs(ItemHeight * 80);
    }
    else{
        self.modifyButton.sd_layout.leftSpaceToView(self.backScrollView , [UIScreen zj_screenWith] * 0.25).topSpaceToView(currentImageView , ItemHeight * 60).widthIs([UIScreen zj_screenWith] * 0.5).heightIs(ItemHeight * 80);
    }
    [self.backScrollView setupAutoContentSizeWithBottomView:self.modifyButton bottomMargin:ItemHeight * 50];
}


-(void)option_modifyButton:(UIButton *)sender{
    [self.navigationController popViewControllerAnimated:YES];
}


- (UIScrollView *)backScrollView{
    if (!_backScrollView ) {
        _backScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0 , navHeight, [UIScreen zj_screenWith], [UIScreen zj_screenHeight] - navHeight)];
        _backScrollView.showsVerticalScrollIndicator = NO;
        _backScrollView.showsHorizontalScrollIndicator = NO;
        _backScrollView.contentSize = _backScrollView.size;
        _backScrollView.backgroundColor = [UIColor whiteColor];
    }
    return _backScrollView;
    
}


-(UIButton *)modifyButton
{
    if (!_modifyButton) {
        _modifyButton = [ToolClass createButtonWithFrame:CGRectMake(0, 0, 1, 1) text:@"修改" textColor:[UIColor whiteColor] imageName:@"" font:18];
        _modifyButton.backgroundColor = [UIColor themeColor];
        _modifyButton.clipsToBounds = YES;
        _modifyButton.layer.cornerRadius = normalCornerRadius;
        [_modifyButton addTarget:self action:@selector(option_modifyButton:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _modifyButton;
}

@end
